//-----------------------------------------------------------------------

// <copyright file="LabelFieldDefinition.cs" company="Jamie Knight">

// Copyright (c) Jamie Knight. All rights reserved.

// </copyright>

//-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Data;

namespace DevKnightlie.WPF.AutoForm.FieldDefinitions
{
    /// <summary>
    /// Field definition which generates a text block rather than an input field
    /// </summary>
    /// <remarks>PropertyName can be empty, in which case the Title is used as static text. If Property is not empty then the text is bound to the named property</remarks>
    public class LabelFieldDefinition : BaseFieldDefinition
    {

        #region Methods

        public override void BuildInputControl()
        {
            ContentControl result = new ContentControl()
            {
                Focusable = false
            };
            TextBlock block = new TextBlock()
            {
                TextAlignment = System.Windows.TextAlignment.Left,
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            if (String.IsNullOrWhiteSpace(PropertyName))
            {
                Binding blockBinding = new Binding(PropertyName);
                BindingOperations.SetBinding(block, TextBlock.TextProperty, blockBinding);
            }
            else
            {
                block.Text = Title;
            }
            result.Content = block;
            ContainerControl = result;
            InputControl = null;
        }

        #endregion

    }
}
